{extend name="base"/}
{block name="resources"}
{/block}
{block name="main"}


<!-- 搜索框 -->
<div class="ns-single-filter-box">

    <div class="layui-form">
        <div class="layui-input-inline">
            <input type="text" id="search_text" name="search_text" placeholder="请输入企业名称" autocomplete="off" class="layui-input">
            <button type="button" class="layui-btn layui-btn-primary" lay-filter="search" lay-submit>
                <i class="layui-icon">&#xe615;</i>
            </button>
        </div>
    </div>
</div>

<!-- 会员标签列表 -->
<table id="label_info" lay-filter="label_info" ></table>


<script type="text/html" id="action">
    <div class="ns-table-btn">
        <a class="layui-btn" lay-event="detail">查看详情</a>
        {{#  if(d.status == 0){  }}
        <a class="layui-btn" lay-event="pass">审核通过</a>
        <a class="layui-btn" lay-event="refuse">审核拒绝</a>
        {{#  }  }}
    </div>
</script>


{/block}
{block name="script"}
<script>
    var form, table;
    layui.use(['form'], function() {
        form = layui.form;
        var repeat_flag = false;

        table = new Table({
            elem: '#label_info',
            url: ns.url("admin/memberopenaccount/enterpriselist"),
            cols: [
                [
                {
                    field: 'enterprise_name',
                    title: '企业名称',
                    width: '10%',
                    unresize:'false'
                },{
                    unresize:'false',
                    field: 'full_address',
                    title: '企业所在地',
                    width: '15%',
                }, {
                    unresize:'false',
                    field: 'address',
                    title: '企业详细地址',
                    width: '10%',
                }, {
                    unresize:'false',
                    field: 'tyshxydm',
                    title: '统一社会信用代码',
                    width: '15%',
                }, {
                    unresize:'false',
                    field: 'shxyzyxq_time_type',
                    title: '社会信用证有效期',
                    width: '15%',
                    templet: function (data) {
                        if (data.id_card_time_type==1){
                            return '永久';
                        } else {
                            return data.shxyzyxq_start_time+'~'+data.shxyzyxq_end_time;
                        }

                    }
                },{
                    unresize:'false',
                    field: 'status',
                    title: '状态',
                    width: '12%',
                    templet: function (data) {
                        if (data.status==0){
                            return '待审核';
                        } else if(data.status==1){
                            return '审核通过';
                        } else {
                            return '审核拒绝';
                        }

                    }
                }, {
                    unresize:'false',
                    field: 'create_time',
                    title: '创建时间',
                    width: '15%',
                    templet: function (data) {
                        return ns.time_to_date(data.create_time); //创建时间转换方法
                    }
                },{
                    unresize:'false',
                    title: '操作',
                    width: '8%',
                    toolbar: '#action'
                }
                ]
            ],
        });

        /**
         * 监听工具栏操作
         */
        table.tool(function(obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'detail': //编辑
                    location.href = ns.url("admin/memberopenaccount/enterprisedetail?account_id="+data.account_id)
                    break;
                case 'pass': //通过
                    passApply(data.account_id);
                    break;
                case 'refuse': //拒绝
                    refuseApply(data.account_id);
                    break;
            }
        });

        //通过申请
        function passApply(account_id) {
            if (repeat_flag) return false;
            repeat_flag = true;
            layer.confirm('确定要通过该进件记录吗?', function() {
                $.ajax({
                    url: ns.url("admin/memberopenaccount/pass"),
                    data: {
                        "account_id": account_id,
                    },
                    dataType: 'JSON',
                    type: 'POST',
                    success: function(res) {
                        layer.msg(res.message);
                        repeat_flag = false;

                        if (res.code == 0) {
                            table.reload();
                        }
                    }
                });
            }, function () {
                layer.close();
                repeat_flag = false;
            });
        }

        //拒绝申请
        function refuseApply(account_id) {
            if (repeat_flag) return false;
            repeat_flag = true;
            layer.confirm('确定要拒绝该进件记录吗?', function() {
                $.ajax({
                    url: ns.url("admin/memberopenaccount/fail"),
                    data: {
                        "account_id": account_id,
                    },
                    dataType: 'JSON',
                    type: 'POST',
                    success: function(res) {
                        layer.msg(res.message);
                        repeat_flag = false;

                        if (res.code == 0) {
                            table.reload();
                        }
                    }
                });
            }, function () {
                layer.close();
                repeat_flag = false;
            });
        }

        // 搜索
        form.on('submit(search)', function(data){
            table.reload({
                page: {
                    curr: 1
                },
                where: data.field
            });
        });
    });

</script>
{/block}